package com.orangecy.infrastructure.persistent.repository;

import com.orangecy.infrastructure.persistent.DO.SkuDO;
import com.orangecy.infrastructure.persistent.DTO.SkuDTO;
import com.orangecy.infrastructure.persistent.common.AbstractDAO;
import com.orangecy.infrastructure.persistent.common.BaseMapper;
import com.orangecy.infrastructure.persistent.common.Convert;
import com.orangecy.infrastructure.persistent.mapper.CrudSkuMapper;
import org.apache.ibatis.annotations.Mapper;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author : orangeCy.奕
 * @Product : 猎豹养成产品源码
 * @Time : 2021/10/29
 * @Desc :
 */
@Mapper
public class CrudSkuDAO extends AbstractDAO<SkuDO> implements Convert<SkuDO, SkuDTO> {

    @Resource
    private CrudSkuMapper crudSkuMapper;

    @Override
    public BaseMapper<SkuDO> getMapper() {
        return crudSkuMapper;
    }

    /**
     * 根据规格ids获取所有规格信息
     * 假设三个规格 红色 黄色 蓝色
     * @param ids
     * @return
     */
    public List<SkuDTO> getSkusById(List<Long> ids) {
        return convertDTOList(crudSkuMapper.getList(ids));
    }

    @Override
    public SkuDTO convertDTO(SkuDO d) {
        SkuDTO skuDTO = new SkuDTO();
        skuDTO.setSkuId(d.getSkuId());
        skuDTO.setSkuName(d.getSkuName());
        skuDTO.setPrice(d.getPrice());
        return skuDTO;
    }
}